package com.zhoutao123.jsp;

import javax.servlet.http.HttpServlet;
import java.util.concurrent.locks.LockSupport;

public class Code2 extends HttpServlet {
  static Thread t1;
  static Thread t2;

  public static void main(String[] args) {
    String data = "1A2B3C4D5E6F7G8H9J0I";
    t1 =
        new Thread(
            () -> {
              int i = 0;
              while (i < data.length()) {
                System.out.print(data.charAt(i));
                i += 2;
                LockSupport.unpark(t2);
                LockSupport.park();
              }
            });
    t2 =
        new Thread(
            () -> {
              int j = 1;
              while (j < data.length()) {
                LockSupport.park();
                System.out.print(data.charAt(j));
                j += 2;
                LockSupport.unpark(t1);
              }
            });

    t1.start();
    t2.start();
  }
}
